package com.zjitc.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: ${赵诚挚}
 * @Date: 2024/6/21 10:58
 */
@Component
public class MetaHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 设置新增动作的createdTime时间为当前的日期对象
        this.setFieldValByName("gmtCreate", new Date(), metaObject);
        this.setFieldValByName("gmtModified", new Date(), metaObject);

        // 设置乐观锁默认为1
        this.setFieldValByName("version", 1, metaObject);
        this.setFieldValByName("isDeleted", 0, metaObject);


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 设置修改动作的updateTime时间为当前的日期对象
        this.setFieldValByName("gmtModified", new Date(), metaObject);
    }
}